﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.Connect;
using System.Data.SqlClient;
using Model;
using System.Data;

namespace WebService.Datalayer
{
    public class DBRoles
    {
       Database db = new Database();
        SqlParameter[] listParameter;

        /// <summary>
        /// SelectRolesAll
        /// </summary>
        /// <returns></returns>
        public DataSet SelectRolesAll()
        {
            return db.GetDataset("sp_SelectRolesAll");
        }

        /// <summary>
        /// SelectRolesByAndRoleID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectRolesByAndRoleID(Roles obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@RoleID", obj.RoleID),
            };
            return db.GetDataSetWithParameter("sp_SelectRolesByAndRoleID", listParameter);
        }

        /// <summary>
        /// DeleteRole
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int DeleteRole(Roles obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@RoleID", obj.RoleID),
            };
            return db.ExcuteQueryWithParamater("sp_DeleteRole", listParameter);
        }

        /// <summary>
        /// InsertRole
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertRole(Roles obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@RoleID", obj.RoleID),
                new SqlParameter("@RoleName", obj.RoleName),
                new SqlParameter("@IsDelete", obj.IsDelete),
            };
            return db.ExcuteQueryWithParamater("sp_InsertRole", listParameter);
        }

        /// <summary>
        /// UpdateRole
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateRole(Roles obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@RoleID", obj.RoleID),
                new SqlParameter("@RoleName", obj.RoleName),
                new SqlParameter("@IsDelete", obj.IsDelete),
            };
            return db.ExcuteQueryWithParamater("sp_UpdateRole", listParameter);
        }
    }
}
